<?php 
    /**
	 *判断是否是通过手机访问
	 */
	 function isMobile() {
		// 如果有HTTP_X_WAP_PROFILE则一定是移动设备
		if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) {
			return true;
		}
		//如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
		if (isset($_SERVER['HTTP_VIA'])) {
			//找不到为flase,否则为true
			return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
		}
		//判断手机发送的客户端标志,兼容性有待提高
		if (isset($_SERVER['HTTP_USER_AGENT'])) {
			$clientkeywords = array('nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp',
					'sie-', 'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone', 'ipod', 'blackberry', 'meizu',
					'android', 'netfront', 'symbian', 'ucweb', 'windowsce', 'palm', 'operamini', 'operamobi',
					'openwave', 'nexusone', 'cldc', 'midp', 'wap', 'mobile');
			// 从HTTP_USER_AGENT中查找手机浏览器的关键字
			if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
				return true;
			}
		}
		//协议法，因为有可能不准确，放到最后判断
		if (isset($_SERVER['HTTP_ACCEPT'])) {
			// 如果只支持wml并且不支持html那一定是移动设备
			// 如果支持wml和html但是wml在html之前则是移动设备
			if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) {
				return true;
			}
		}
		return false;
	}
	?>

<script src="<?php echo isMobile() ? Yii::app()->getConfig('generalscripts').'echart/mchart/echarts.js' : Yii::app()->getConfig('generalscripts').'echart/pchart/echarts.js';
                            //echo  Yii::app()->getConfig('generalscripts').'echart/pchart/echarts.js';
	           ?>"></script>

<script type='text/javascript'>
    var graphUrl="<?php echo Yii::app()->getController()->createUrl("admin/statistics/sa/graph"); ?>";

     function Ygetdata(arr)
     {
           var data = [];	
           if(Object.prototype.toString.call(arr)  !== '[object Array]') return data;
           var len = arr.length;
			if(len ==0 ) return data;
			for(var i=0; i<len; i++)
			{
					data[i] = [Math.random()*10,parseInt(arr[i]),100];
			}

			return data;
     }

 	    require.config({
 	        paths: {
 	          // echarts: 'http://localhost/lime/scripts'
 	           echarts:"<?php  echo  isMobile()?Yii::app()->getConfig('generalscripts').'echart/mchart':Yii::app()->getConfig('generalscripts').'echart/pchart';
	                              // echo Yii::app()->getConfig('generalscripts').'echart/pchart';
	
	                       ?>"
   	           
 	        }
 	    });
        require(
            [
                'echarts',
                'echarts/chart/bar',
                'echarts/chart/line',
                'echarts/chart/map',
                'echarts/chart/scatter'
            ],
 	
        function (ec) {
            //--- 折柱 ---
            var myChart = ec.init(document.getElementById('main1'));
            var ydata  = Ygetdata(eval('<?php echo json_encode($ass_arr);?>'));
            myChart.setOption({
                title : {
                    text: '<?php echo $thisSurveyTitle."的得分分布情况" ;?>',
                    <?php if($userid) echo "subtext: '抽样调查来自您所在班级'" ;?>
                },
 
                tooltip : {
                    trigger: 'axis',
                    showDelay : 2,
                    formatter : function (params) {
                        if (params.value.length > 1) {
                            return params.seriesName + ' :<br/>'
                               + params.value[1];
                        }
                        else {
                            return params.seriesName + ' :<br/>'
                               + params.name;
                        }
                    },
                    axisPointer:{
                        show: false,
                        type : 'cross',
                        lineStyle: {
                            type : 'dashed',
                            width : 1
                        }
                    }
                },
                toolbox: {
                    show : true,
                    feature : {
                        mark : {show: false},
                        dataView : {show: true, readOnly: false},
                        magicType : {show: false},
                        //restore : {show: true},
                        saveAsImage : {show: false}
                    }
                },
                calculable : true,
                xAxis : [
                    {
                        type : 'value',
                        scale:true,
                       data : [1,2,3,4,5,6,7,8,9,10],
                        //data : idata,
                       show: false
                    }
                ],
                yAxis : [
                    {
                    	type : 'value',
                        scale:true
                    }
                ],
                series : [
                    {
                        name:'问卷得分',
                        type:'scatter',
                        data: ydata,
                        markPoint : {
                            data : [
                                {type : 'max', name: '最大值'},
                                {type : 'min', name: '最小值'}
                            ]
                        },
                        markLine : {
                            data : [
                                {type : 'average', name: '平均值'}
                            ]
                        }
                           
                    }
                ]
            });
           // myChart.clear();
            //myChart.dispose();
        }
    );
    
        var myChart = echarts.init(document.getElementById('main2'));

        // 指定图表的配置项和数据
        var option = {
            title: {
                text: 'ECharts 入门示例'
            },
            tooltip: {},
            legend: {
                data:['销量']
            },
            xAxis: {
                data: ["衬衫","羊毛衫","雪纺衫","裤子","高跟鞋","袜子"]
            },
            yAxis: {},
            series: [{
                name: '销量',
                type: 'bar',
                data: [5, 20, 36, 10, 10, 20]
            }]
        };

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    
</script>

        <div id='statsContainer'>
            <div id='statsHeader'>
                <div class='statsSurveyTitle'><?php echo $thisSurveyTitle; ?></div>
                <div class='statsNumRecords'><?php echo gT("Total records in survey")." : $totalrecords"; ?></div>
            </div>
         <?php if( ! empty($ass_arr)){  ?>
            <div id="main1" style="height:300px;border:1px solid #ccc;padding:10px;"></div>
            <div id="main2" style="height:300px;border:1px solid #ccc;padding:10px;"></div>
           <?php }?>
            <?php if (isset($statisticsoutput) && $statisticsoutput) { echo $statisticsoutput; } ?><br />
        </div>
<?php 
    echo templatereplace(file_get_contents(getTemplatePath($sTemplatePath)."/endpage.pstpl"),array(), $redata);
?>

